#include <bits/stdc++.h>

using namespace std;

#define int long long
const int N = 15;
int a[N];
void solve()
{
    int n , s;
    cin >> n >> s;
    for(int i = 0;i < n;i ++) cin >> a[i];
    int ans = min(abs(s - a[0]) , abs(s - a[n - 1])) + a[n - 1] - a[0];
    cout << ans << endl;
}
signed main()
{
    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}